package com.zx.callback.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zx.callback.common.enums.MessageEnumTable;
import com.zx.callback.common.enums.OrderStateEnum;
import com.zx.callback.common.handler.PageBean;
import com.zx.callback.dao.OrderInfoMapper;
import com.zx.callback.po.OrderInfo;
import com.zx.callback.service.OrderSearchService;
import com.zx.callback.vo.JsonResult;
import com.zx.callback.vo.order.OrderAndUserInfoVO;
import com.zx.callback.vo.order.OrderListParamVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：yanst
 * @since: 2017/12/7
 * @history：(date editor desc)
 */
@Service
public class OrderSearchServiceImpl extends BaseService implements OrderSearchService {

    @Resource
    private OrderInfoMapper orderInfoMapper;

    @Override
    public JsonResult<OrderInfo> validOrderIsPay(String orderNum) {
        OrderInfo orderInfo = orderInfoMapper.selectByOrderNum(orderNum);
        if (orderInfo == null) {
            return JsonResult.getJsonObj(MessageEnumTable.ORDER_NOT_EXIST);
        }
        if (orderInfo.getState().byteValue() != OrderStateEnum.UNPAID.getKey()
                && orderInfo.getState() != OrderStateEnum.OVERTIME_UNPAID.getKey()
                && orderInfo.getState() != OrderStateEnum.ORDER_CANCEL_UNPAY.getKey()) {
            logger.error("当前订单已经付款，订单信息：order={}", JSON.toJSONString(orderInfo));
            return JsonResult.getJsonObj(MessageEnumTable.PAY_ALREADY);
        }
        return JsonResult.getOkJsonObj(orderInfo);
    }
}
